#include <InputListener.h>

class CNetrekClientApplication;
class Ogre::Camera;
class Ogre::SceneManager;
class Ogre::Overlay;
struct Ogre::FrameEvent;
class CBaseGameState;
class CGameWorld;
class CServerConnection;
class CInputManager;
class CUIManager;


enum ENetrekClientState
{
    eNetrekClientState_Invalid,
    eNetrekClientState_Quit,
    eNetrekClientState_GetServerName,
    eNetrekClientState_Login,
    eNetrekClientState_CreateNewLogin,
    eNetrekClientState_TeamAndShipSelect,
    eNetrekClientState_InGame
};


class CNetrekClientListener : public Ogre::FrameListener, public IInputListener
{
public:
    CNetrekClientListener(CNetrekClientApplication*);

    void Initialize();
    void Cleanup();
    bool frameStarted(const Ogre::FrameEvent& evt);
    bool frameEnded(const Ogre::FrameEvent& evt);


    void OnKeyboardAcquired();
    void OnMouseAcquired();
    void MouseMoved(int dx, int dy, int dz);
    void MousePressed(EMouseButtonID eMouseButtonID);
    void MouseReleased(EMouseButtonID eMouseButtonID);
    void KeyPressed(EKeyboardButtonID eKeyboardButtonID);
    void KeyReleased(EKeyboardButtonID eKeyboardButtonID);
    void CharEntered(WCHAR wch);
    void KeyUp(int keyCode);
    void KeyDown(int keyCode);

    ENetrekClientState GetCurrentState() const { return m_eStateCur; }
    void MoveToNewState(ENetrekClientState eNewState) { m_eStatePending = eNewState; }

    CNetrekClientApplication* GetApp() { return m_pApp; }
    CServerConnection* GetServerConnection() { return m_pServerConnection; }
    CGameWorld* GetGameWorld() { return m_pGameWorld; }
    Ogre::Camera* GetCamera() { return m_pCamera; }
    Ogre::SceneManager* GetSceneManager() { return m_pSceneManager; }
    Ogre::Root* GetRoot();
    CInputManager* GetInputManager() { return m_pInputManager; }
    CUIManager* GetUIManager() { return m_pUIManager; }

    float GetTimeSinceLastFrameAsFloat() const { return m_flTimeSinceLastFrame; }

private:

    void TransitionToNewState();

    CGameWorld* m_pGameWorld;
    CNetrekClientApplication* m_pApp;
    Ogre::Camera* m_pCamera;
    Ogre::SceneManager* m_pSceneManager;
    CServerConnection* m_pServerConnection;

    CBaseGameState* m_pGameState;
    CInputManager* m_pInputManager;

    CUIManager* m_pUIManager;

    ENetrekClientState m_eStateCur;
    ENetrekClientState m_eStatePending;

    float m_flTimeSinceLastFrame;

    Ogre::Overlay* m_pDebugOverlay;
    int m_vkLastDown;
};

